#include <iostream>
#include "buf.h"
#include "error.h"
#include <stdio.h>

using namespace std;

int main()
{
  BufMap MyMap;
  //DB myDB;
  File* file1;
  File* file2;
  File* file3;
  File* file4;

  //Error myError;
  Status mystat;
  //
  // start testing
  //first insert 
  mystat=MyMap.insert(file1,10,20);
  if (mystat!=OK)  cout<<"fail!"<<endl;
  // 
  mystat=MyMap.insert(file2,10,30);
  if (mystat!=OK)  cout<<"fail!"<<endl;
  //
  file3=file1;
  mystat=MyMap.insert(file3,10,20);
  if (mystat==BUFMAPERROR) cout<<"Error Correct"<<endl;
  //look up
  unsigned int temp;
  mystat=MyMap.lookup(file1,10,temp);
  if (mystat!=OK) cout<<"fail!"<<endl; else cout<<temp<<endl;
  //
  mystat=MyMap.lookup(file2,10,temp);
  if (mystat!=OK) cout<<"fail!"<<endl; else cout<<temp<<endl;
  //
  mystat=MyMap.lookup(file1,20,temp);
  if (mystat==BUFMAPNOTFOUND) cout<<"Error Correct"<<endl;
  //
  mystat=MyMap.lookup(file4,10,temp);
  if (mystat==BUFMAPNOTFOUND) cout<<"Error Correct"<<endl;
  // remove
  mystat=MyMap.remove(file4,10);
  if (mystat==BUFMAPNOTFOUND) cout<<"Error Correct"<<endl;
  //
  mystat=MyMap.remove(file1, 30);
  if (mystat==BUFMAPNOTFOUND) cout<<"Error Correct"<<endl;
  //
  mystat=MyMap.remove(file1,10);
  if (mystat!=OK) cout<<"fail!"<<endl;
  //
  mystat=MyMap.lookup(file1,10,temp);
  if (mystat==BUFMAPNOTFOUND) cout<<"delete successfully"<<endl;
   
  return 0;
}
